package com.musicalevents.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.musicalevents.service.BasicService;
import com.musicalevents.service.PasswordEncodingService;


@Controller
public class ApplicationController {

	@Autowired
	private BasicService basicService;
	
	@Autowired
	private PasswordEncodingService pwdService;
	
	@ModelAttribute
	public void populateModel(Model m) {		
		m.addAttribute("allBands", basicService.getAllBands());
		m.addAttribute("allTowns", basicService.getAllTowns());
		m.addAttribute("allPlaces", basicService.fetchAllPlacesLinkTown());
		m.addAttribute("allEvents", basicService.fetchAllEventsLinkPlaceTown());
	}
	
	@RequestMapping(value="/home.htm", method=RequestMethod.GET)
	public String goToHomepage() {
		//CustomUserDetails u = (CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		//pwdService.encodeAndSaveUserPassword(u.getID());
		
		
		return ("home");
	}
}
